/*
 * Created by SharpDevelop.
 * User: c0148643
 * Date: 11/05/2010
 * Time: 11:12
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Data;
using System.Data.SQLite;
using System.Collections.Generic;
using Microsoft.Win32;

namespace pontoIndividual
{

    public class controleEvento: IDisposable
    {
        public static controleEvento Instancia = new controleEvento();
        
        public static string acao = "";
        private bool mapeouEvento = false;      
        
        public string getAcao()
        {
            return controleEvento.acao;
        }

        protected controleEvento()
        {
            
        }

        public void addMapeamentoEvento()
        {
            if (mapeouEvento == false)
            {
                SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
                mapeouEvento = true;
            }
        }

        public void delMapemanetoEvento()
        {
            if(mapeouEvento == true)
                SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
        }


        static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
        {
            if(e.Reason == SessionSwitchReason.SessionLock)
            {
                controleEvento.acao = "Bloqueado";
                MainForm.horarioBloqueio = DateTime.Now;
            }
            
            if(e.Reason == SessionSwitchReason.SessionUnlock)
            {
                controleEvento.acao = "Desbloqueado";
                MainForm.instancia.voltar();                
            }
        }


        #region IDisposable Members

        public void Dispose()
        {
            try
            {
                delMapemanetoEvento();
            }
            catch (Exception exc) { }   
        }

        #endregion
    }


}
